package com.xbongbong.pro.rabbitmq.consumer;/*/*/

import com.alibaba.fastjson.JSON;
import com.xbongbong.paas.toolbox.wrap.XbbResponse;
import com.xbongbong.pro.message.pojo.dto.ConsistencySyncRabbitMqDTO;
import com.xbongbong.pro.message.pojo.vo.ConsistencySyncRabbitMqVO;
import com.xbongbong.pro.rabbitmq.binders.ConsistencySyncConsumerBinder;
import com.xbongbong.pro.rabbitmq.constant.ConsistencySyncBinderConstant;
import com.xbongbong.pro.rabbitmq.feign.ConsistencySyncFeignClient;
import feign.RetryableException;
import java.util.Locale;
import javax.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.stream.annotation.EnableBinding;
import org.springframework.cloud.stream.annotation.StreamListener;
import org.springframework.context.i18n.LocaleContextHolder;

/**
 *
 * @author 魏荣杰
 * @date 2019/6/11 9:31
 * @since v1.0
 * @version v1.0
 */
@EnableBinding(ConsistencySyncConsumerBinder.class)
public class ConsistencySyncListener {
    private static Logger logger = LoggerFactory.getLogger(ConsistencySyncListener.class);

    @Resource
    private ConsistencySyncFeignClient consistencySyncFeignClient;

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_CUSTOMER_INPUT)
    public void syncCustomer(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) {
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        try {
            Locale locale = LocaleContextHolder.getLocale();
            String lang = locale.toString();
            logger.info("syncCustomer receive message = " + JSON.toJSONString(consistencySyncRabbitMqDTO));
            response = consistencySyncFeignClient.syncCustomer(consistencySyncRabbitMqDTO, lang);
            logger.info("syncCustomer message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
        } catch (RetryableException e) {
            logger.error("ConsistencySyncListener.syncCustomer RetryableException case by Read timed out");
        } catch (Exception e) {
            logger.error("ConsistencySyncListener.syncCustomer Exception", e);
        }

    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_CONTACT_INPUT)
    public void syncContact(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) {
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        try {
            Locale locale = LocaleContextHolder.getLocale();
            String lang = locale.toString();
            response = consistencySyncFeignClient.syncContact(consistencySyncRabbitMqDTO, lang);
            logger.info("syncContact message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
        } catch (RetryableException e) {
            logger.error("ConsistencySyncListener.syncContact RetryableException case by Read timed out");
        } catch (Exception e) {
            logger.error("ConsistencySyncListener.syncContact Exception", e);
        }
    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_CONTRACT_INPUT)
    public void syncContract(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) {
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        try {
            Locale locale = LocaleContextHolder.getLocale();
            String lang = locale.toString();
            response = consistencySyncFeignClient.syncContract(consistencySyncRabbitMqDTO, lang);
            logger.info("syncContract message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
        } catch (RetryableException e) {
            logger.error("ConsistencySyncListener.syncContract RetryableException case by Read timed out");
        } catch (Exception e) {
            logger.error("ConsistencySyncListener.syncContract Exception", e);
        }

    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_OPPORTUNITY_INPUT)
    public void syncOpportunity(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) {
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        try {
            Locale locale = LocaleContextHolder.getLocale();
            String lang = locale.toString();
            response = consistencySyncFeignClient.syncOpportunity(consistencySyncRabbitMqDTO, lang);
            logger.info("syncOpportunity message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
        } catch (RetryableException e) {
            logger.error("ConsistencySyncListener.syncOpportunity RetryableException case by Read timed out");
        } catch (Exception e) {
            logger.error("ConsistencySyncListener.syncOpportunity Exception", e);
        }

    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_PRODUCT_INPUT)
    public void syncProduct(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) {
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        try {
            Locale locale = LocaleContextHolder.getLocale();
            String lang = locale.toString();
            response = consistencySyncFeignClient.syncProduct(consistencySyncRabbitMqDTO, lang);
            logger.info("syncProduct message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
        } catch (RetryableException e) {
            logger.error("ConsistencySyncListener.syncProduct RetryableException case by Read timed out");
        } catch (Exception e) {
            logger.error("ConsistencySyncListener.syncProduct Exception", e);
        }
    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_USER_INPUT)
    public void syncUser(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) {
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        try {
            Locale locale = LocaleContextHolder.getLocale();
            String lang = locale.toString();
            response = consistencySyncFeignClient.syncUser(consistencySyncRabbitMqDTO, lang);
            logger.info("syncUser message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
        } catch (RetryableException e) {
            logger.error("ConsistencySyncListener.syncUser RetryableException case by Read timed out");
        } catch (Exception e) {
            logger.error("ConsistencySyncListener.syncUser Exception", e);
        }

    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_SUPPLIER_INPUT)
    public void syncSupplier(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) {
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        try {
            Locale locale = LocaleContextHolder.getLocale();
            String lang = locale.toString();
            response = consistencySyncFeignClient.syncSupplier(consistencySyncRabbitMqDTO, lang);
            logger.info("syncSupplier message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
        } catch (RetryableException e) {
            logger.error("ConsistencySyncListener.syncSupplier RetryableException case by Read timed out");
        } catch (Exception e) {
            logger.error("ConsistencySyncListener.syncSupplier Exception", e);
        }

    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_WAREHOUSE_INPUT)
    public void syncWarehouse(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) {
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        try {
            Locale locale = LocaleContextHolder.getLocale();
            String lang = locale.toString();
            response = consistencySyncFeignClient.syncWarehouse(consistencySyncRabbitMqDTO, lang);
            logger.info("syncWarehouse message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
        } catch (RetryableException e) {
            logger.error("ConsistencySyncListener.syncWarehouse RetryableException case by Read timed out");
        } catch (Exception e) {
            logger.error("ConsistencySyncListener.syncWarehouse Exception", e);
        }

    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_QUOTATION_INPUT)
    public void syncQuotation(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) {
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        response = consistencySyncFeignClient.syncQuotation(consistencySyncRabbitMqDTO, lang);
        logger.info("syncQuotation message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_PURCHASE_INPUT)
    public void syncPurchase(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) {
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        response = consistencySyncFeignClient.syncPurchase(consistencySyncRabbitMqDTO, lang);
        logger.info("syncPurchase message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_BATCH_FLOW_BILL_INPUT)
    public void syncBatchFlowBill(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) {
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        response = consistencySyncFeignClient.syncBatchFlowBill(consistencySyncRabbitMqDTO, lang);
        logger.info("syncBatchFlowBill message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_SEQ_SEARCH_INPUT)
    public void syncSeqSearch(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO) {
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        response = consistencySyncFeignClient.syncSeqSearch(consistencySyncRabbitMqDTO, lang);
        logger.info("syncSeqSearch message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_PAYMENT_INPUT)
    public void syncPayment(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO){
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        response = consistencySyncFeignClient.syncPayment(consistencySyncRabbitMqDTO, lang);
        logger.info("syncPayment message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_PAYPLAN_INPUT)
    public void syncPayPlan(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO){
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        response = consistencySyncFeignClient.syncPayPlan(consistencySyncRabbitMqDTO, lang);
        logger.info("syncPayPlan message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_CLUE_INPUT)
    public void syncClue(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO){
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        response = consistencySyncFeignClient.syncClue(consistencySyncRabbitMqDTO, lang);
        logger.info("syncClue message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_MARKET_ACTIVITY_INPUT)
    public void syncMarketActivity(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO){
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        response = consistencySyncFeignClient.syncMarketActivity(consistencySyncRabbitMqDTO, lang);
        logger.info("syncMarketActivity message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_COMPETITOR_INPUT)
    public void syncCompetitor(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO){
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        response = consistencySyncFeignClient.syncCompetitor(consistencySyncRabbitMqDTO, lang);
        logger.info("syncCompetitor message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_INVOICE_INPUT)
    public void syncInvoice(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO){
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        response = consistencySyncFeignClient.syncInvoice(consistencySyncRabbitMqDTO, lang);
        logger.info("syncInvoice message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
    }

    @StreamListener(value = ConsistencySyncBinderConstant.SYNC_CONTRACT_OUTSTOCK_INPUT)
    public void syncContractOutStock(ConsistencySyncRabbitMqDTO consistencySyncRabbitMqDTO){
        XbbResponse<ConsistencySyncRabbitMqVO> response;
        Locale locale = LocaleContextHolder.getLocale();
        String lang = locale.toString();
        response = consistencySyncFeignClient.syncContractOutStock(consistencySyncRabbitMqDTO, lang);
        logger.info("syncContractOutStock message=" + JSON.toJSONString(consistencySyncRabbitMqDTO) + "\n response=" + JSON.toJSONString(response));
    }
}
